package chapter08_class

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test10_TraitOver
 * Package: chapter08_class
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-07-03
 *          Time: 14:45
 */

//特征的混入
object Test10_TraitOver {
  def main(args: Array[String]): Unit = {
    val stu10 = new Stu10
    stu10.increase() //Knowledge increase

    //钻石问题
    val myFootBall = new MyFootBall
    println(myFootBall.describe())

  }
}

//特征混入钻石问题
trait Ball {
  //球类的特征 描述
  def describe(): String = "ball"
}

//颜色
trait ColorBall extends Ball {
  var color: String = "red"

  override def describe(): String = color + "_" + super.describe()
}

//种类
trait CategoryBall extends Ball {
  var category: String = "foot"

  override def describe(): String = category + "_" + super.describe()
}

//定义一个自定球的类
class MyFootBall extends CategoryBall with ColorBall {
  //特质是从后往前叠加的
  //my ball is a foot_red_ball  输出这样的结果继承关系是 extends ColorBall with CategoryBall
  //那么MyFoolBall的super 调用的是CategoryBall CategoryBall的super是Color  然是在是Ball 下面同理
  //my ball is a red_foot_ball  继承关系是extends CategoryBall with ColorBall
  override def describe(): String = "my ball is a " + super.describe()

}



trait Knowledge10 {
  var amount: Int = 0

  def increase(): Unit = {
    println("Knowledge increase")
  }
}

trait Talent10 {
  def singing(): Unit

  def dancing(): Unit

  def increase(): Unit = {
    println("talent increase")
  }
}

class Stu10 extends Person9 with Talent10 with Knowledge10 {
  override def dancing(): Unit = println("dancing")

  override def singing(): Unit = println("singing")

  //两个特质当中 存在相同的 increase 所以必须要重写这个方法
  override def increase(): Unit = {
    //这个super方法 执行的是Knowledge increase
    //如果父类当中也有 increase方法 也是执行 Knowledge increase
    //叠加效果是从后往前叠加的 如果将Talent10 放在最后 那么执行结果就是 Talent10
    super.increase()
  }


}